<?php
 
require_once('../../../../wp-config.php');
require_once('../../../../wp-includes/functions.php');


global $table_prefix, $wpdb, $post;
$table_name = $wpdb->prefix."collect";

$posturl = $_POST['posturl'];
$posttitle = $_POST['posttitle'];
$postimg = $_POST['postimg'];
$userid = $_POST['userid'];
$metavalue = $_POST['metavalue'];
$postid = $_POST['postid'];
$ip=getenv("REMOTE_ADDR");
$date=date("Y-m-d H:i:s");

$result = $wpdb->get_results("SELECT * FROM $table_name WHERE c_userid =".$userid." and c_posttitle = '".$posttitle."'");
if(empty($result))
{
    if($userid != 0)
    {
        $sql="INSERT INTO $table_name (c_userid, c_posttitle, c_posturl, c_postid, c_ip,c_time) VALUES ('" .$userid. "','" .$posttitle. "','" . $posturl. "','" .$postid. "','" .$ip. "','" .$date. "')";
        $r = mysql_query($sql);
        if($r)
        {
            add_post_meta($postid, '_postcollect',0,true);
            $collect_count = get_post_meta($postid, '_postcollect', true);
            if($collect_count != null)
            {
                $collect_count = $collect_count+1;
                update_post_meta($postid, '_postcollect', $collect_count);
            }
            echo $collect_count;    
        }
        else
        {
            echo '数据存储失败';
            
        }
     }
     else
     {
        echo '视频收藏失败,请先进行登录！';
     }   
}
else
{
    
    echo '抱歉!不能重复收藏';

}


?>